package com.javasm.commons.exception;

import com.javasm.commons.entity.AxiosResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;

@RestControllerAdvice
public class MvcExceptionHandler {

    @ExceptionHandler(MvcException.class)
    public AxiosResult doMvcException(MvcException e){
        return AxiosResult.error(e.getE());
    }

    @ExceptionHandler(Exception.class)
    public AxiosResult defaultException(Exception e){
        return AxiosResult.error(e.getMessage());
    }
}
